package net.fdukedom.epicurus.plugin;

import net.fdukedom.epicurus.domain.entity.Plugin;
import net.fdukedom.epicurus.domain.entity.MessageType;

import java.util.Map;
import java.util.Set;

/**
 * @author Dmitry Y. Kochelaev
 */
public class MessageTypesLoader extends CollectionLoader<Plugin, MessageType> {
    public MessageTypesLoader(Plugin plugin) {
        super(plugin);
    }

    public MessageType parseAttributes(Map<String, String> attributes) {
        return new MessageType(attributes.get("name"), item);
    }

    public Set<MessageType> getLoadedCollection() {
        return item.getMessageTypes();
    }

    public void disposeElement(MessageType element) {
        item.getMessageTypes().remove(element);
        element.setPlugin(null);
    }

    public void addElement(MessageType element) {
        element.setPlugin(item);
        item.getMessageTypes().add(element);
    }
}
